<html>
    <head>
        <script type="text/javascript" src="src/lib/jquery.js"></script>
        <script type="text/javascript" src="src/limitedStorage.js"></script>
        <script type="text/javascript" src="src/crossDomainStorage.js"></script>
    </head>
    <body>
        <script type="text/javascript">
        $(document).ready(function(){

            /*
             * Testing limited local storage
             */
            lstorage = limitedStorage({maxItems: 20, prefix: '_testing_'});

            //Note that the specified number of max items (20) are smaller
            //than the number of keys to store in the following loop (100):
            for (var i = 0; i<=100; i++) {
                lstorage.setItem("key-" + i, {
                    'a_tag': 'a value - ' + i, 
                    'other_tag': 
                    'other value - ' + i
                });
            }

            //There must be only the last 20 values
            for (var i = 0; i<=100; i++) {
                value = lstorage.getItem("key-"+i);
                if(value !== null){
                    //you'll need a <div id="results"></div> in your test page...
                    document.getElementById('results').innerHTML += "<br/>found: key-" + i + ", value: " + JSON.stringify(value);
                }
            }

            document.getElementById('results').innerHTML += "<br/>-----------------------<br/>";

            /*
             * Testing cross-domain storage
             */
            cdstorage = crossDomainStorage({
                origin: "http://localhost:1920",
                path: "/localstorage/crossd_iframe.html"
            });

            //Now we can use the object to set or get values from a shared localStorage space:
            console.log(cdstorage.getItem('a',function() {
                console.log('in cdStorage~')
            }))

            cdstorage.getItem('b',function() {
                console.log('in cdStorage~b')
            }).then(function(e) {
                console.log(e, 'cdcdcdstorage')
            })
            cdstorage.setItem('a_cross-domain_key', "The value should be a string, or it will be converted to string..");
            //This will store the previous value asynchronously, so we need callbacks:
            cdstorage.getItem('a_cross-domain_key', function(key, value) {
                document.getElementById('results').innerHTML += "<br/>Cross Domain callback: (" + key + ": " + value + ")";
            });


            cdstorage.getItem('ddd', function(k,v) {
                console.log('iiiiiii', k, v)
            })

            cdstorage.getItem('dddd', function(k,v) {
                console.log('iiiiiii - - - -', k, v)
            })


            cdstorage = crossDomainStorage({
                origin: "http://localhost:5584",
                path: "/localstorage/crossd_iframe.html"
            });

            cdstorage.setItem('pond-jwt-token', 'fufufufuf')

        });
        </script>
        <div id="results"></div>
    </body>
</html>
